package com.springboot.controller;

import com.springboot.exception.AccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

@Controller
public class MyErrorController {
    //模拟服务器内部错误500
    @GetMapping("/err")
    public String err() {
        int i = 10 / 0;
        return "manger";
    }

    //模拟客户端错误。以get请求来找post请求
    @PostMapping("/err2")
    public String err2() {
        return "manger";
    }

    @GetMapping("/err3")
    public String err3(String name) {
        //如果访问的不是tom，就认为无权访问
        if (!"tom".equals(name)) {
            throw new AccessException("Access自定义异常处理...");
        }
        return "manger";
    }
}
